package com.cxrj.zhsq.userManage.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cxrj.zhsq.annotation.SystemControllerLog;
import com.cxrj.zhsq.userManage.service.MenuService;

@RestController
public class MenuController {

	@Resource
	private MenuService menuService;

	/**
	 * @Description: 查询菜单树
	 * @param
	 */
	@RequestMapping("selectMenuTree")
	public List<Map<String, Object>> selectMenuTree(HttpServletRequest request) {
		List<Map<String, Object>> list = menuService.selectMenuTree(new HashMap<String, Object>(), request);
		return list;
	}

	/**
	 * @Description: 查询所有菜单树
	 * @param
	 */
	@RequestMapping("selectMenuTreeAll")
	public List<Map<String, Object>> selectMenuTreeAll(HttpServletRequest request) {
		List<Map<String, Object>> list = menuService.selectMenuTreeAll(new HashMap<String, Object>(), request);
		return list;
	}

	/**
	 * @Description: 验证code是否重复
	 * @param map
	 */
	@RequestMapping(value = "checkMenuCode", method = RequestMethod.POST)
	public Map<String, Object> checkMenuCode(@RequestParam Map<String, Object> map) {
		return menuService.selectMenuCode(map);
	}

	/**
	 * @Description: 新增组织
	 * @param map
	 *            参数map
	 */
	@RequestMapping(value = "insertMenu", method = RequestMethod.POST)
	@SystemControllerLog(description = "新增菜单")
	public Map<String, Object> insertMenu(@RequestParam Map<String, Object> map, HttpSession session) {
		Map<String, Object> resultMap = new HashMap<>();
		try {
			menuService.insertMenu(map);
			resultMap.put("result", 0);
		} catch (Exception e) {
			resultMap.put("result", -1);
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * @Description: 修改菜单
	 * @param map
	 *            参数map
	 */
	@RequestMapping(value = "updateMenu", method = RequestMethod.POST)
	@SystemControllerLog(description = "修改菜单")
	public Map<String, Object> updateMenu(@RequestParam Map<String, Object> map, HttpSession session) {
		Map<String, Object> resultMap = new HashMap<>();
		try {
			// map.put("editAccount",session.getAttribute("userAccount"));
			menuService.updateMenu(map);
			resultMap.put("result", 0);
		} catch (Exception e) {
			resultMap.put("result", -1);
		}
		return resultMap;
	}

	/**
	 * @Description: 删除菜单
	 * @param map
	 *            参数map
	 * @Date: 15:55 2017/11/30
	 */
	@RequestMapping(value = "deleteMenu", method = RequestMethod.POST)
	@SystemControllerLog(description = "删除菜单")
	public Map<String, Object> deleteMenu(@RequestParam Map<String, Object> map) {
		Map<String, Object> resultMap = new HashMap<>();
		try {
			menuService.deleteMenu(map);
			resultMap.put("result", 0);
		} catch (Exception e) {
			resultMap.put("result", -1);
		}
		return resultMap;
	}

	/**
	 * @Description: 查询菜单权限
	 * @param map
	 *            参数map
	 */
	@RequestMapping(value = "selectByRole", method = RequestMethod.POST)
	public Map<String, Object> selectByRole(String roleId) {
		return menuService.selectByRole(roleId);
	}
}
